package com.jpemartin.jgt;

import java.awt.Point;
import java.util.ArrayList;


/** a FireControl that fires according to a set sequence, in a loop.
 *  
 */
public class FireSequence implements FireControl {
   
   protected int currentSequence;
   protected int moveCount;
   protected int shotCount;
   // I'm using "Point" because it's a convenient way to put 2 ints,
   // not because this has anything to do with a 2D point.
   protected ArrayList<Point> _rythm;
   
   public FireSequence() {
      _rythm=new ArrayList<Point>();
   }
   
   /** Add "shotCount" shots to the sequence, with a pause of "coolingTime"
    *  between each shot.
    */
   public void addSequence(int coolingTime, int shotCount) {
      _rythm.add(new Point(coolingTime, shotCount));    
   }
   
   public boolean shouldFire() {
      boolean should=false;
      moveCount++;
      if (moveCount>_rythm.get(currentSequence).x) {
         should=true;
         shotCount++;
         moveCount=0;
      }
      if (shotCount>=_rythm.get(currentSequence).y) {
         currentSequence=(currentSequence+1) % _rythm.size();
         shotCount=0;
      }
      return should;
   }

}
